package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.evaluate.SearchTeacherEvaluationAllInfoListResult;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;
import com.net.wanjian.networkhospitalmanager.view.LRatingBar;
import com.zhy.autolayout.utils.AutoUtils;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by lidongcai on 17/7/20.
 * Email:  lidongcaiocc@163.com
 */

public class EvaluateDetailsTeacherStarAdapter extends RecyclerBaseAdapter<SearchTeacherEvaluationAllInfoListResult.DataBean.ComprehensiveEvaluationItemListBean, EvaluateDetailsTeacherStarAdapter.ViewHolder> {

    public EvaluateDetailsTeacherStarAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_evaluate_details_teacher_star, parent, false);
        AutoUtils.auto(view);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, SearchTeacherEvaluationAllInfoListResult.DataBean.ComprehensiveEvaluationItemListBean item, int position) {

        holder.itemEvaluateDetailsTeacherStarTv.setText(URLDecoderUtil.getDecoder(item.getEvaluationItemName())+":");

        String starNum = "0";
        DecimalFormat starFormat = new DecimalFormat("#");
        String format = "0";
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
        float valueResult = Float.parseFloat(item.getEventEvaluationItemValue());
        if (valueResult != 0){
            format = decimalFormat.format(valueResult);
            starNum = starFormat.format(valueResult);
        }
        //设置星星和值
        holder.itemEvaluateDetailsTeacherStarRatingbar.setStar(Float.parseFloat(starNum));
        holder.itemEvaluateDetailsTeacherStarScoreTv.setText(format);
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_evaluate_details_teacher_star_tv)
        TextView itemEvaluateDetailsTeacherStarTv;
        @BindView(R.id.item_evaluate_details_teacher_star_ratingbar)
        LRatingBar itemEvaluateDetailsTeacherStarRatingbar;
        @BindView(R.id.item_evaluate_details_teacher_star_score_tv)
        TextView itemEvaluateDetailsTeacherStarScoreTv;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
